package com.ymatou.iapi.godmch.service;

import java.util.List;






import net.sf.json.JSONArray;

import org.json.JSONObject;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.ymatou.iapi.godmch.parameter.AllparentsmchResp;
import com.ymatou.iapi.godmch.parameter.mchInfo;
import com.ymatou.iapi.godmch.parameter.parentInfo;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
*获取商户所有上级商户身份Call
*FreeMaker Template自动生成代码
*/
public class allparentsmchCall extends YmatouBaseCall{
	private static String opurl ="api/mch/allparents";
	
	public allparentsmchCall() {
		super(EnvSetup.getSystemUrl("godmch_iapi"),opurl,"GET","PARAM");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	
	 public String getStatus1()
		{
			  return getString("status");
		}
			
	    public String getMessage()
		{
			 return getString("msg");
		}
	    

		public List<parentInfo> getAllParentsList() {
			List<parentInfo> data = null;
			try {
//				JSONArray jsonArray = JSONArray.fromObject(new JSONObject(getString("result").toString()).getString("parents"));
//				
//				data=(List<parentInfo>) JSONArray.toCollection(jsonArray, parentInfo.class);

				data = (List<parentInfo>) new Gson().fromJson(getJsonObject().get("result").getAsJsonObject().get("parents").getAsJsonArray().toString(), new TypeToken<List<parentInfo>>() {}.getType());

				//data = (List<parentInfo>) FormatUtil.GSONToObject(jsonArray, parentInfo.class);
				//FormatUtil.JSONToObject(new JSONObject(getString("result").toString()).getString("parents"), AllparentsmchResp.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return data;
		}
}